
Page({
  /**
   * 页面的初始数据
   */
  data: {
    schema: [
      {
        label:'顶部距离',
        prop:'top',
        type:'number',
        value: 0
      },
      {
        label:'左边界距离',
        prop:'left',
        type:'number',
        value: 0
      },
      {
        label:'初始速度 (仅在 iOS 下生效)',
        prop:'velocity',
        type:'number'
      },
      {
        label:'滚动动画时长 (仅在 iOS 下生效)',
        prop:'duration',
        type:'number',
        value: 300
      },
      {
        label:'是否启用滚动动画',
        prop:'animated',
        type:'picker',
        labelOptions:['true', 'false'], //选项
        valueOptions:[true, false], //选项对应的值
        value: true
      },
    ],
    formData: {
      top: 0,
      left: 0,
      velocity: 0,
      duration: 300,
      animated: true
    },
    title: '',
    result: '',
    remark: '',
    webUrl: ''
  },
  onLoad(options) {
    console.log('options', options)
    wx.setNavigationBarTitle({
      title: options.title,
    })

    this.setData({
      title: options.title,
      zh:options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    })
    wx.createSelectorQuery().select('#scroll-id').node().exec((res) => {
      this.scrollViewContent = res[0].node
    })
    wx.createSelectorQuery().select('#scroll-id2').node().exec((res) => {
      this.scrollViewContent2 = res[0].node
    })
  },
  getFormData(e) {
    const formData = {}
    this.data.schema.forEach(item => {
      if(item.type === 'number') {
        if(!isNaN(+e.detail.formData[item.prop])) {
          formData[item.prop] = +e.detail.formData[item.prop]
        }
      } else {
        formData[item.prop] = e.detail.formData[item.prop]
      }
    })
    this.setData({
      formData: formData
    })
    console.log('formData', formData);
  },
  choose1() {
    this.scrollViewContent.scrollTo(this.data.formData)
  },
  choose2() {
    this.scrollViewContent2.scrollTo(this.data.formData)
  }
})